export const duration = 2000;

export const msg = (title) => {
	uni.showToast({
		title: title,
		mask: true,
		icon: "none",
		duration: duration
	})
}

export const notLogged = () => {
	msg("请先登录")
	setTimeout(() => {
		uni.navigateTo({
			url: "/pages/mine/index"
		})
	}, duration)
}

export const back = () => {
	setTimeout(() => {
		uni.navigateBack()
	}, duration)
}

export function chunkArray(data, chunkSize = 3) {
	// 使用Array.from和map函数生成索引数组，然后用slice切割原始数组  
	return Array.from({
			length: Math.ceil(data.length / chunkSize)
		}, (_, i) =>
		data.slice(i * chunkSize, i * chunkSize + chunkSize)
	);
}

export function isImageOrVideoUrl(url) {
	// 提取URL的文件扩展名  
	const extension = url.toLowerCase().split('.').pop();

	// 定义图片和视频常见的扩展名  
	const imageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp']; // 添加其他图片格式  
	const videoExtensions = ['mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv']; // 添加其他视频格式  

	// 检查URL是否是图片  
	if (imageExtensions.includes(extension)) {
		return 'image';
	}

	// 检查URL是否是视频  
	if (videoExtensions.includes(extension)) {
		return 'video';
	}

	// 如果不是图片也不是视频，返回false  
	return false;
}